package com.lzwork.gpt.utility.common;

import com.lzwork.gpt.utility.caller.GptCallResult;
import com.lzwork.gpt.utility.thread.CallerThread;
import com.lzwork.gpt.utility.thread.MultiCaller;
import com.lzwork.utility.pair.StringPair;

/**
 * @author LiZheng
 * @date 2024年3月14日 17:00:15
 */

public abstract class MultiChatCaller extends MultiCaller
{
	protected abstract StringPair getJob();

	protected abstract void afterJob(String key, GptCallResult cr);

	@Override
	protected CallerThread createJob(String server)
	{
		ParserCaller caller = new ParserCaller(server, false);
		return new CallerThread(caller, this);
	}

	@Override
	public void doJob(CallerThread ct)
	{
		StringPair sp;

		synchronized (this)
		{
			sp = getJob();
		}

		if (sp != null)
		{
			String key = sp.getKey();
			String content = sp.getValue();

			GptCallResult cr = ct.getCaller().callChat(content, null, null);
			afterJob(key, cr);
		}
	}
}
